package org.example.movies.dao.impl;

import org.example.movies.dao.IUserDao;
import org.example.movies.pojo.TUser;
import org.example.movies.utils.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements IUserDao {
    @Override
    public List checkUser() {
        JdbcTemplate temp = new JdbcTemplate(JDBCUtils.getDataSource());
        String sql="select username,password from t_user";
        List<TUser> list = temp.query(sql, new BeanPropertyRowMapper<TUser>(TUser.class));
        return list;
    }

    @Override
    public int insertUser(TUser user) {
        JdbcTemplate temp = new JdbcTemplate(JDBCUtils.getDataSource());
        String sql="insert into t_user(email,username,password) value(?,?,?)";
        int update = temp.update(sql,user.getEmail(),user.getUsername(),user.getPassword());
        return update;
    }
}
